Coordinate graceful shutdown with Home Assistant OS#6851
Open
sairon wants to merge 1 commit into
Open
Conversation
On a reboot or power off triggered from the API, enter the haos-pre-shutdown.target systemd target before stopping Home Assistant Core, so the OS can stop the console CLI cleanly instead of letting it restart-loop while the CLI plugin is torn down. Entering the target is best-effort and a no-op on OS releases that don't have it. For host shutdowns not initiated by Supervisor, the SIGTERM handler now inspects the systemd manager state. When it is "stopping", Supervisor runs the managed Core.shutdown() to stop Core, apps and plugins gracefully before tearing itself down; on a plain Supervisor restart the state is "running", so only Supervisor stops as before. The manager state is exposed by every systemd version, so this works regardless of the OS release. Add the SystemState D-Bus enum and Systemd.get_system_state() for the state lookup. Refs home-assistant/operating-system#4642 Refs home-assistant/operating-system#4719 Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
14 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Proposed change
On a reboot or power off triggered from the API, enter the haos-pre-shutdown.target systemd target before stopping Home Assistant Core, so the OS can stop the console CLI cleanly instead of letting it restart-loop while the CLI plugin is torn down. Entering the target is best-effort and a no-op on OS releases that don't have it.
For host shutdowns not initiated by Supervisor, the SIGTERM handler now inspects the systemd manager state. When it is "stopping", Supervisor runs the managed Core.shutdown() to stop Core, apps and plugins gracefully before tearing itself down; on a plain Supervisor restart the state is "running", so only Supervisor stops as before. The manager state is exposed by every systemd version, so this works regardless of the OS release.
Add the SystemState D-Bus enum and Systemd.get_system_state() for the state lookup.
Refs home-assistant/operating-system#4642
Refs home-assistant/operating-system#4719
Type of change
Additional information
Checklist
ruff format supervisor tests)If API endpoints or add-on configuration are added/changed: